package com.dhcc.bpm.modules.scf.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dhcc.bpm.common.segmentId.LocalCacheIdGenerator;
import com.dhcc.bpm.modules.scf.dto.ScfOperationLogInfoDTO;
import com.dhcc.bpm.modules.scf.entity.ScfOperationLogInfo;
import com.dhcc.bpm.modules.scf.mapper.ScfOperationLogInfoMapper;
import com.dhcc.bpm.modules.scf.service.IScfOperationLogInfoService;
import com.dhcc.bpm.modules.scf.vo.ScfOperationLogInfoVO.ScfOperationLogInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 操作轨迹表 服务实现类
 *
 * @author liuguoting
 * @since 2023-11-13
 */
@Service
public class ScfOperationLogInfoServiceImpl extends ServiceImpl<ScfOperationLogInfoMapper, ScfOperationLogInfo> implements IScfOperationLogInfoService {
    /**
     * id生成器
     */
    @Autowired
    private LocalCacheIdGenerator localCacheIdGenerator;

    /**
     * 分页查询操作日志列表
     *
     * @param page
     * @param scfOperationLogInfo
     * @return
     */
    @Override
    public IPage<ScfOperationLogInfoVO> selectScfOperationLogInfoPage(IPage<ScfOperationLogInfoVO> page, ScfOperationLogInfoDTO scfOperationLogInfo) {
        return page.setRecords(baseMapper.selectScfOperationLogInfoPage(page, scfOperationLogInfo));
    }

    @Override
    public Boolean saveOperationLogInfo(ScfOperationLogInfo scfOperationLogInfo) {
        // 生成日期
        SimpleDateFormat date = new SimpleDateFormat("YYYYMMdd");
        String formatdate = date.format(new Date());
        // 生成时间
        SimpleDateFormat timeFormat = new SimpleDateFormat("HHmmss");
        String formTime = timeFormat.format(new Date());
        // 设置rowId
        scfOperationLogInfo.setRowId("Log" + formatdate + formTime + localCacheIdGenerator.nextId());
        // 保存
        return save(scfOperationLogInfo);
    }

    @Override
    public Boolean bachSaveOperationLogInfo(List<ScfOperationLogInfo> scfOperationLogInfoList) {
        // 生成日期
        SimpleDateFormat date = new SimpleDateFormat("YYYYMMdd");
        String formatdate = date.format(new Date());
        // 生成时间
        SimpleDateFormat timeFormat = new SimpleDateFormat("HHmmss");
        String formTime = timeFormat.format(new Date());
        for (ScfOperationLogInfo scfOperationLogInfo : scfOperationLogInfoList) {
            // 设置rowId
            scfOperationLogInfo.setRowId("Log" + formatdate + formTime + localCacheIdGenerator.nextId());
        }
        return saveBatch(scfOperationLogInfoList);
    }

}
